package com.k7.mobile.platform.bo.impl;import java.util.ArrayList;import java.util.List;import javax.servlet.http.HttpServletRequest;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.commons.lang.StringUtils;import com.k7.mobile.platform.bo.IUserBO;import com.k7.mobile.platform.dao.IUserDAO;import com.k7.mobile.platform.dataobject.UserDO;import com.k7.mobile.platform.exception.BOException;import com.qike.java.api.UserInfo;import com.qike.java.pojo.User;import com.qike.java.util.HttpClientUtil;

public class UserBOImpl extends BaseBOImpl implements IUserBO {

	private IUserDAO userDAO;
	private UserInfo userInfo;			@Override
	public void addUser(UserDO userDO) throws BOException {
		if(userDO == null)
			throw new BOException("创建用户失败，用户对象为空.");
		
		try{
			userDAO.addUser(userDO);
		}catch(Exception e){
			log.error("UserBOImpl:addUser 创建用户失败.", e);
			throw new BOException("创建用户失败.", e);
		}
	}

	@Override
	public UserDO getUserById(Long userId)
			throws BOException {
		if(userId == null)
			return null;
		
		try{
			return userDAO.getUserById(userId);
		}catch(Exception e){
			log.error("UserBOImpl:getUserById 根据ID获取用户详情失败.", e);
			throw new BOException("根据ID获取用户详情失败.", e);
		}
	}

	@Override
	public List<UserDO> getUserList(UserDO queryDO)
			throws BOException {
		if(queryDO == null)
			throw new BOException("根据帖子ID查询用户列表失败.查询条件对象为空.");
		
		try{
			return userDAO.getUserList(queryDO);
		}catch(Exception e){
			log.error("UserBOImpl:getUserList 根据帖子ID获取用户列表失败.", e);
			throw new BOException("根据帖子ID获取用户列表失败.", e);
		}
	}

	@Override
	public void updateUser(UserDO userDO)
			throws BOException {
		if(userDO == null)
			throw new BOException("更新用户信息失败.更新对象为空.");
		
		try{
			userDAO.updateUser(userDO);
			
		}catch(Exception e){
			log.error("UserBOImpl:updateUser 更新用户信息失败.", e);
			throw new BOException("更新用户信息失败.", e);
		}
	}
	
	
	public void setUserDAO(IUserDAO userDAO) {
		this.userDAO = userDAO;
	}

	
	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	@Override
	public User get7kUser(Long userId) {
		if(userId == null)
			return null;
		
		List<String> userList = new ArrayList<String>();
		userList.add(userId.toString());
		List<User> list = userInfo.getInfoByUids(userList);
		
		if(list == null || list.size() == 0)
			return null;
		
		return list.get(0);
	}

	@Override
	public User isLogin(HttpServletRequest request) {
		User user = userInfo.isLogin(request);
		return user;
	}

	
	
	@Override
	public List<User> getUsers(List<String> uids) {
		if(uids == null || uids.size() == 0)
			return null;
		
		List<User> list = userInfo.getInfoByUids(uids);
		if(list==null||list.isEmpty()){
			return null;	
		}
		return list;
	}	
	
}
